using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using UMEVOR.BLL;
using UMEVOR.DTO;
using UMEVOR.VO;

public partial class Cadastro_CadT_HIST_NOTICIA : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack && !this.IsCallback)
            EstadoInicial();
        Acesso();
    }
    protected void gvHistorico_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.txtDataInicio.Text = Request.Form[txtDataInicio.UniqueID];
        this.txtDataFim.Text = Request.Form[txtDataFim.UniqueID];

        this.gvHistorico.PageIndex = e.NewPageIndex;
        BLLT_HIST_NOTICIA bllHistNoticia = new BLLT_HIST_NOTICIA();
        gvHistorico.DataSource = bllHistNoticia.consultar(DateTime.Parse(txtDataInicio.Text), DateTime.Parse(txtDataFim.Text));
        gvHistorico.DataBind();
    }
    protected void btLimpar_Click(object sender, ImageClickEventArgs e)
    {
        EstadoInicial();
    }
    protected void btPesquisar_Click(object sender, ImageClickEventArgs e)
    {
        DateTime inicio, fim;

        this.txtDataInicio.Text = Request.Form[txtDataInicio.UniqueID];
        this.txtDataFim.Text = Request.Form[txtDataFim.UniqueID];

        if (DateTime.TryParse(txtDataInicio.Text, out inicio) == false)
            inicio = DateTime.Now;

        if (DateTime.TryParse(txtDataFim.Text, out fim) == false)
            fim = DateTime.Now;

        BLLT_HIST_NOTICIA bllHistNoticia = new BLLT_HIST_NOTICIA();
        gvHistorico.DataSource = bllHistNoticia.consultar(inicio, fim);
        gvHistorico.DataBind();
    }
    private void EstadoInicial()
    {
        txtDataFim.Text = string.Empty;
        txtDataInicio.Text = string.Empty;
        BLLT_HIST_NOTICIA bllHistNoticia = new BLLT_HIST_NOTICIA();
        gvHistorico.DataSource = bllHistNoticia.consultar(DateTime.Now, DateTime.Now);
        gvHistorico.DataBind();
        txtDataInicio.Focus();
    }
    private void Acesso()
    {
        BLLT_USUARIO bllUsuario = new BLLT_USUARIO();

        string acesso = bllUsuario.validarAcesso(Session["Usuario"].ToString(), "CadT_HIST_NOTICIA.aspx");

        if (acesso == "M")
        {
            btPesquisar.Visible = true;
            btLimpar.Visible = true;
        }
        else if ((acesso == "C") || (acesso == ""))
        {
            btPesquisar.Visible = false;
            btLimpar.Visible = false;
        }
    }
}

